<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>抢购成功</title>
    <script type="text/javascript" src="js/axios.min.js"></script>
    <script type="text/javascript" src="js/qs.min.js"></script>
    <script type="text/javascript" src="js/request.js"></script>
    <style type="text/css">
        #main {
            font-family: Consolas,serif;
            text-align: center;
            margin: auto;
            position: absolute;
            width: 300px;
            height: 300px;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }
    </style>
</head>
<body>

<div id="main">
    <strong>
        <span id="message">抢购成功,后台正在处理您的请求,请等待页面跳转...</span>
    </strong>
</div>

<script type="text/javascript">
    window.onload = function () {
        let params = new URLSearchParams(location.search);
        let key = params.get("key");
        const SUCCESS = 2;
        const READY = 3;
        const FAIL1 = 4;
        setInterval(function () {
            request("http://api.shopping.com/seckill/seckillStatus?sessionId=" + key.split("_")[0] + "&skuId=" + key.split("_")[1], "get").then(seckillStatus => {
                if (seckillStatus === READY) {
                    location.href = "pay.html?sn=" + key.split("_")[2];
                } else if (seckillStatus === FAIL1) {
                    alert("由于您未设置默认收货地址,本次秒杀失败");
                } else if (seckillStatus !== SUCCESS) {
                    location.href = "index.html";
                }
            })
        }, 3000);
    }
</script>

</body>
</html>